<?php

namespace process;

use app\services\ActivityService;
use app\services\CoinService;
use app\services\OrderService;
use app\services\UserLevelService;
use app\services\UserPropertyService;
use app\services\UserTeamService;
use support\Db;
use Workerman\Crontab\Crontab;

class Task
{
    public function onWorkerStart()
    {
        new Crontab('*/5 * * * * *', function() {
            OrderService::autoCancel();
            OrderService::autoReceive();
        });

        new Crontab('0 0 0 1 * *', function() {
            Db::beginTransaction();
            try {
                UserPropertyService::clearContribution();   //每月自动清空贡献值
                UserPropertyService::extraRebate();     //每月自动发放额外返利
                UserTeamService::clearCurrentMonthRecommendOrderCount();    //每月自动清空当月推荐订单数

                Db::commit();
            } catch (\Exception $e) {
                Db::rollBack();
                echo $e->getMessage() . $e->getTraceAsString();
            }
        });

//        new Crontab('0 0 0 5 8 *', function() {
//            Db::beginTransaction();
//            try {
//                UserPropertyService::clearContribution();   //每月自动清空贡献值
//                UserPropertyService::extraRebate();     //每月自动发放额外返利
//                UserTeamService::clearCurrentMonthRecommendOrderCount();    //每月自动清空当月推荐订单数
//
//                Db::commit();
//            } catch (\Exception $e) {
//                Db::rollBack();
//                echo $e->getMessage() . $e->getTraceAsString();
//            }
//        });
    }
}